package com.carlinfo.stu_ques.common.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

public class FileUtil
{
	public boolean writeObject(OutputStream os, Object obj)
	{
		ObjectOutputStream oos = null;
		try
		{
			BufferedOutputStream bos = new BufferedOutputStream(os);
			oos = new ObjectOutputStream(bos);
			/* 存储对象 */
			oos.writeObject(obj);
			/* 控水管 */
			oos.flush();
			return true;
		} catch (IOException e)
		{
			e.printStackTrace();
		} catch (Exception e)
		{
			e.printStackTrace();
		} finally
		{
			try
			{
				if (oos != null)
				{
					oos.close();
					oos = null;
				}

			} catch (IOException e)
			{
				e.printStackTrace();
			}
		}
		return false;

	}

	/* 输入流 */
	public Object readObject(InputStream is)
	{
		ObjectInputStream ois = null;

		try
		{
			BufferedInputStream bis = new BufferedInputStream(is);
			ois = new ObjectInputStream(bis);
			return ois.readObject();
		} catch (IOException e)
		{
			e.printStackTrace();
		} catch (Exception e)
		{
			e.printStackTrace();
		} finally
		{
			try
			{
				if (ois != null)
				{
					ois.close();
					ois = null;
				}

			} catch (IOException e)
			{
				e.printStackTrace();
			}
		}
		return null;

	}

}
